const app = new Vue({
	el:'#app',
	data:{
		Games:[
		{
			id:1,
			name:'WOW',
			date:'1999',
			price:499,
			count:1
		},
		{
			id:2,
			name:'Overwatch',
			date:'2017',
			price:328,
			count:1
		},
		{
			id:3,
			name:'HearthStone',
			date:'2016',
			price:0,
			count:1
		},
		{
			id:4,
			name:'DiabloⅢ',
			date:'2017',
			price:388,
			count:1
		},
		{
			id:5,
			name:'Heroes of the Storm',
			date:'2018',
			price:0,
			count:1
		}
		]
	},
	
	
	methods:{
		increment(index){
			this.Games[index].count++
		},
		decrement(index){
			this.Games[index].count--
		},
		removeBtnClick(index){
			this.Games.splice(index,1)
		}
	},
	
	//计算属性不是函数，只是一个属性，定义方法名不要用动词
	computed:{
		totolPrice(){
			let totolPrice = 0
			for(let i =0; i< this.Games.length;i++){
				totolPrice += this.Games[i].price * this.Games[i].count
			}
			return totolPrice
		}
	},
	
	filters:{
		showPrice(price){
			return'￥'+ price.toFixed(2)
		}
	}
	
})
